import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './registerServiceWorker'

Vue.config.productionTip = false

import * as global from './components/func/func'
Vue.prototype.global = global

import 'font-awesome/css/font-awesome.css'
import './components/css/main.scss'

import i18n from './components/lang/index'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

let quillEditor = require('vue-quill-editor')
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(quillEditor)

let NProgress = require('nprogress')
import 'nprogress/nprogress.css'

//onload
router.beforeEach((to, from, next) => {
  if(to.meta.title){
    document.title = to.meta.title
  }else{
    document.title = 'NOTE MANAGER'
  }
  let user = localStorage.getItem('user_id')
  let passLink = ['/login']

  if(!user  && passLink.indexOf(to.path) === -1){
    window.location.href="/login"
  }else{
    NProgress.start();
    next()
  }
});
//end load
router.afterEach(transition => {
  NProgress.done();
});

new Vue({
  router,
  i18n,
  store,
  render: h => h(App)
}).$mount('#app')
